# class Person:
#     def __init__(self,name,sex,age):
#         self.name = name
#         self.age = age
#         self.sex = sex
#
# class Cat:
#     def __init__(self,name,sex,age):
#         self.name = name
#         self.age = age
#         self.sex = sex
#
# class Dog:
#     def __init__(self,name,sex,age):
#         self.name = name
#         self.age = age
#         self.sex = sex

# class Animal:
#     def __init__(self, name, age, sex):
#         self.name = name
#         self.age = age
#         self.sex = sex
#
# class A:
#     pass
#
# class Person(Animal):
#     pass
#
#
# class Dog(Animal):
#     pass
#
#
# class Cat(Animal):
#     pass

# 继承的优点:

# 继承分为单继承与多继承.
# Person  Dog  Cat : 子类,派生类
# Animal: 父类, 基类, 超类
# 单继承: 使用.
# 多继承:有区别.


# class Animal(object):
#
#     live = '有生命的'
#
#     def __init__(self, name, age, sex):
#         self.name = name
#         self.age = age
#         self.sex = sex
#
#     def eat(self):
#         print(f'self----> {self}')
#         print('动物都需要进食')
#
#
# class Person(Animal):
#     pass
#
# # 1.从类名执行父类的属性.
# # print(Person.__dict__)
# # print(Person.live)
# #
# # Person.eat(55)
#
# # 2. 从对象执行父类的一切.
# # 实例化对象一定一定会执行三件事. 一定会执行__init__
#
# # p1 = Person('dsb', 21, 'laddy_boy')
# # # print(p1.__dict__)
# # print(p1.live)
# # p1.eat()
# # print(f'p1--->{p1}')
# Person.live = 'xxx'
# print(Person.live)

# 注意: 子类以及子类对象只能调用父类的属性以及方法,不能操作(增删改).


# class Animal(object):
#
#     live = '有生命的'
#
#     def __init__(self, name, age, sex):
#         self.name = name
#         self.age = age
#         self.sex = sex
#
#     def eat(self):
#         print(f'self----> {self}')
#         print('动物都需要进食')
#
#
# class Person(Animal):
#
#     def eat(self):
#         print('人类需要进食')
#
#
#
# p1 = Person('dsb', 21, 'laddy_boy')
# # 子类将父类的方法覆盖了,(重写父类的方法)
# p1.eat = '李业'
# p1.eat()  # 对象查找顺序先从对象空间找名字, 子类找名字, 父类找名字.

# 如何既要执行父类方法又要执行子类方法

# 两种解决方式:
# class Animal:
#
#     live = '有生命的'
#
#     def __init__(self, name, age, sex):
#         self.name = name
#         self.age = age
#         self.sex = sex
#
#     def eat(self):
#         print(f'self----> {self}')
#         print('动物都需要进食')
#
#
# class Person(Animal):
#
#     def __init__(self,name, age, sex, hobby):
#         '''
#         self : p1
#         :param name: 怼怼哥
#         :param age: 23
#         :param sex: 不详
#         :param hobby: 吹牛逼
#         '''
#         # 方法一:
#         Animal.__init__(self, name, age, sex)
#         # 方法二:
#         # super(Person, self).__init__(name, age, sex)
#         # super().__init__(name, age, sex)
#         self.hobby = hobby
#
#     def eat(self):
#         print('人类需要进食')
#         super().eat()
#
#
# p1 = Person('怼怼哥', 23, '不详','吹牛逼')
# # print(p1.__dict__)
# p1.eat()



# class Base:
#
#     def __init__(self, num):
#         self.num = num
#
#     def func1(self):
#         print(self.num)
#
# class Foo(Base):
#     pass
#
# obj = Foo(123)
# obj.func1()



# class Base:
#     def __init__(self, num):
#         self.num = num
#
#     def func1(self):
#         print(self.num)
#
# class Foo(Base):
#
#     def func1(self):
#         print("Foo. func1", self.num)
#
# obj = Foo(123)
# obj.func1()


# class Base:
#     def __init__(self, num):  # 2
#         self.num = num
#
#     def func1(self):  # 4
#         print(self.num)  # 123
#         self.func2()  # self ---> obj  # 对象查询顺序:
#
#     def func2(self):
#         print("Base.func2")
#
# class Foo(Base):
#     def func2(self):
#         print("Foo.func2")
#
# obj = Foo(123)  # 1
# obj.func1() # 3
#
#
# class Base:
#     def __init__(self, num):
#         self.num = num
#     def func1(self):
#
#         print(self.num)
#         self.func2()
#
#     def func2(self):
#         print(111, self.num)
#
# class Foo(Base):
#
#     def func2(self):
#         print(222, self.num)
#
# lst = [Base(1), Base(2), Foo(3)]
#
# for obj in lst:
#     obj.func2()


# class Base:
#
#     def __init__(self, num):
#         self.num = num
#
#     def func1(self):
#         print(self.num)
#         self.func2()
#
#     def func2(self):
#         print(111, self.num)
#
#
# class Foo(Base):
#
#     def func2(self):
#         print(222, self.num)
#
#
# lst = [Base(1), Base(2), Foo(3)]
# for obj in lst:
#     obj.func1()


